<template>
  <div>
    <el-row>
      <el-button
        size="mini"
        type="primary"
        icon="el-icon-refresh-left"
        plain
        @click="openData"
        >刷新</el-button
      >
      <el-button
        size="mini"
        type="primary"
        icon="el-icon-refresh-left"
        plain
        @click="onAddQuestion"
        >增加问题</el-button
      >
    </el-row>
    <el-dialog v-model="FShowQuestion" center destroy-on-close>
      <el-form :model="FIndexQuestion" label-width="80px">
        <el-form-item label="问题标题">
          <el-input v-model="FIndexQuestion.FQuestionTitle"></el-input>
        </el-form-item>
        <el-form-item label="关键字">
          <el-input
            v-model="FIndexQuestion.FQuestionKeys"
            placeholder="搜索用的，多个关键子用|切分"
          ></el-input>
        </el-form-item>

        <el-form-item label="问题描述">
          <el-input v-model="FIndexQuestion.FQuestionDescribe"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="FShowQuestion = false">取 消</el-button>
          <el-button type="primary" @click="saveQuestion">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    <div style="height: 15px"></div>
    <el-table
      :data="FQuestionList"
      row-key="FQuestionID"
      border
      highlight-current-row
    >
      <el-table-column prop="FQuestionTitle" label="标题"> </el-table-column>
      <el-table-column prop="FQuestionKeys" label="关键字"> </el-table-column>
      <el-table-column prop="FCreateTime" label="创建时间"> </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" plain size="mini" @click="onEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            plain
            @click="onDesgin(scope.row)"
            >答案</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script lang="ts">
import {
  TBaseCmsMenu,
  TBaseCmsQuestion,
} from "@/baselib/module/cms/BaseCmsApi";
import { IMenuItem } from "@/store";
import TFormBase from "@/views/BaseForm";
export default class TFormCmsQuestionList extends TFormBase {
  private FCmsMuen: TBaseCmsMenu = new TBaseCmsMenu();
  private FIndexQuestion: TBaseCmsQuestion = new TBaseCmsQuestion();
  private FQuestionList: TBaseCmsQuestion[] = [];
  //
  private FShowQuestion: boolean = false;
  public created() {
    let temp = this.zIndexTag?.menuParams.CmsMenu;
    if (temp.FMenuID) {
      this.FCmsMuen = temp;
      if (this.$myStrHelper.stringIsEmptyYW(this.FCmsMuen.FCMSID)) {
        this.$myMsgHelp.msgDialog("参数值不正确【FCMSID】值不可为空");
        return;
      }
    } else {
      this.$myMsgHelp.msgDialog(
        "参数类型不正确,请传入参数[CmsMenu],类型[TBaseCmsMenu]"
      );
      return;
    }
    this.openData();
  }
  private async openData() {
    let lResult = await this.$myBaseCms.GetQuestionListByMenuID(
      this.FCmsMuen.FMenuID
    );
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FQuestionList = lResult.resultData;
  }
  private onAddQuestion() {
    this.FIndexQuestion = new TBaseCmsQuestion();
    this.FIndexQuestion.FCMSID = this.FCmsMuen.FCMSID;
    this.FIndexQuestion.FCMSMenuID = this.FCmsMuen.FMenuID;
    this.FShowQuestion = true;
  }
  private onEdit(qQuestion: TBaseCmsQuestion) {
    this.FIndexQuestion = qQuestion;
    this.FShowQuestion = true;
  }
  private async saveQuestion() {
    let lResult = await this.$myBaseCms.SaveQuestion(this.FIndexQuestion);
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FShowQuestion = false;
  }
  private onDesgin(qQuestion: TBaseCmsQuestion) {
    let lTag: IMenuItem = {
      menuIndexName: "TFormCmsEditor_" + qQuestion.FQuestionID,
      menuComponent: "TFormCmsEditor",
      menuTitle: "问题设计_" + qQuestion.FQuestionTitle,
      menuIcon: "",
      menuParams: {
        CmsID: qQuestion.FCMSID,
        CmsMenuID: qQuestion.FCMSMenuID,
        CmsQuestionID: qQuestion.FQuestionID,
      }, //参数
      menuChildren: [],
    };
    this.$myEvenBus.addTag(lTag);
  }
}
</script>